package com.qyer.search.filter;/**
 * User: Z J Wu Date: 2016/01/13 Time: 10:31 Package: com.qyer.search.filter
 */

import static com.qyer.log.WarningLogger.logWarning;
import static com.qyer.search.model.lastminute.SKU.naSKU;

import com.qyer.search.model.SearchParameter;
import com.qyer.search.model.SearchParameterOrigin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.BitSet;
import java.util.HashSet;
import java.util.Set;

public class OnSaleValidator implements AbstractValidator {

  private static final Logger LOGGER = LoggerFactory.getLogger(OnSaleValidator.class);

  public OnSaleValidator() {
  }

  private final int ESTIMATED_ID_SIZE = 100000;

  // fixme which one is better?
  private Set<Integer> validIDSet = new HashSet<>(ESTIMATED_ID_SIZE);
  private BitSet validIDBitSet = new BitSet(ESTIMATED_ID_SIZE);

  public void addId(int id) {
    this.validIDSet.add(id);
    this.validIDBitSet.set(id);
  }

  @Override public boolean isValid(SearchParameter sp, int id) {
    boolean isValid = (id > 0) && this.validIDBitSet.get(id);
    if (!isValid) {
      //logWarning(naSKU(id), sp, null);
    }
    return isValid;
  }

  @Override public boolean isValid(SearchParameterOrigin sp, int id) {
    boolean isValid = (id > 0) && this.validIDBitSet.get(id);
    if (!isValid) {
      //logWarning(naSKU(id), sp, null);
    }
    return isValid;
  }

}
